package com.object.module.cbb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.object.configuration.utils.PageUtils;
import com.object.configuration.utils.Query;
import com.object.dao.cbb.CbbAddressDao;
import com.object.module.cbb.entity.CbbAddressEntity;
import com.object.module.cbb.service.CbbAddressService;
import com.object.module.cbb.service.CbbUserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("cbbAddressService")
public class CbbAddressServiceImpl extends ServiceImpl<CbbAddressDao, CbbAddressEntity> implements CbbAddressService {

    @Autowired
    private CbbUserService userService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<CbbAddressEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if (StringUtils.isNotEmpty(key)) {
            wrapper.eq("ad_phone", key);
        }
        IPage<CbbAddressEntity> page = this.page(
                new Query<CbbAddressEntity>().getPage(params),
                wrapper
        );
        for (CbbAddressEntity record : page.getRecords()) {
            record.setUser(userService.getById(record.getAdUrId()));
        }
        return new PageUtils(page);
    }

    //查询详情
    @Override
    public CbbAddressEntity info(Integer adId) {
        return null;
    }

    //查询全部
    @Override
    public List<CbbAddressEntity> listAll() {
        List<CbbAddressEntity> list = list();
        for (CbbAddressEntity cbbAddressEntity : list) {
            cbbAddressEntity.setUser(userService.getById(cbbAddressEntity.getAdUrId()));
        }
        return list;
    }

}